<template>
	<view class="index-container"></view>
</template>

<script>
	export default {
		data() {
			return {
				inviteOpenId: '',
				inviteId: ''
			};
		},
		onLoad(options) {
			console.log('========>> 进入首页参数：', options);
			this.loadData(options);
		},
		methods: {
			async loadData(options) {
				this.checkSharePathvariable(options)
			},
			/**
			 * 检查是否有分享码 
			 * data.inviteOpenId: 推广链接
			 * scene.sharecode: 小程序码
			 */
			async checkSharePathvariable(options) {
				let that = this;
				let hasFetchUserinfo = false;
				try {
					if (options.data) {
						let data = JSON.parse(decodeURIComponent(options.data))

						if (data.inviteOpenId && data.inviteOpenId !== undefined) {
							that.inviteOpenId = data.inviteOpenId;
						}
					}
				} catch (e) {
					// console.log('非分享链接')
				}

				try {
					if (options.scene) {
						const scene = decodeURIComponent(options.scene)

						const urlData = scene.split("=")
						const sharecode = urlData[1]

						that.inviteId = sharecode;
					}
				} catch (e) {
					// console.log('非小程序码扫码访问')
				}
			}
		}
	}
</script>